using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

using System;
using System.Windows.Forms;
using System.Security.Principal;
using System.Threading;


namespace Agron.UI.SmartClient
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);

            Application.Run(new LoginForm());
        }

        /// <summary>
        /// Handles the ThreadException event of the global <see cref="Application"/>.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Threading.ThreadExceptionEventArgs"/> instance containing the event data.</param>
        static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            System.Diagnostics.Trace.TraceError("Application_ThreadException()");
            System.Diagnostics.Trace.TraceError(e.Exception.Message);

            if ((null != e.Exception) && ExceptionPolicy.HandleException(e.Exception, Constants.SmartClientExceptionPolicy))
                throw e.Exception;
        }
    }
}